﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vds2465Telegrams
{
	public abstract class UserData
	{
		#region public constants

		public const byte UserData01Priority						= 0x01;
		public const byte UserData02StatusChangeReport2Confirm		= 0x02;
		public const byte UserData03StatusChangeConfirm				= 0x03;
		public const byte UserData04StatusChangeReport				= 0x04;

        public const byte UserData10Query                           = 0x10;
        public const byte UserData11Error                           = 0x11;

        public const byte UserData20State                           = 0x20;
        public const byte UserData24BlockState                      = 0x24;
        public const byte UserData26BlockStateAll                   = 0x26;

		public const byte UserData30Measurements					= 0x30;
		public const byte UserData35GPSCoordinates					= 0x35;

		public const byte UserData40Test							= 0x40;
		public const byte UserData41TestConfirm						= 0x41;
		public const byte UserData42SecurityCode					= 0x42;
		public const byte UserData44History							= 0x44;
		public const byte UserData48ConnectionPath					= 0x48;

		public const byte UserData50DateAndTime						= 0x50;
		public const byte UserData51ManufacturerId					= 0x51;
		public const byte UserData52CommunicationAddressS2			= 0x52;
		public const byte UserData53CommunicationAddressS3			= 0x53;
		public const byte UserData54AsciiChars						= 0x54;

        public const byte UserData55SupportedUserDataTypes          = 0x55;
        public const byte UserData56IdentificationNumber            = 0x56;

		public const byte UserData60NetStatus						= 0x60;
		public const byte UserData61TransportServiceType			= 0x61;
		public const byte UserData62SourceNetAddress				= 0x62;

		public const byte UserData70DataBlock						= 0x70;
		public const byte UserData71DataBlockFinal					= 0x71;
		public const byte UserData72DataBlockValid					= 0x72;
		public const byte UserData73TelegramCounter					= 0x73;
		public const byte UserData74Container						= 0x74;

		public const byte UserDataFFConnectionNotNeeded				= 0xFF;

		#endregion public constants

		#region private member variables

		private readonly byte _dataType;

		#endregion private member variables

		#region constructor

		public UserData(byte dataType)
		{
			_dataType = dataType;
		}

		#endregion constructor

		#region getters

		public byte DataType { get { return _dataType; } }

		#endregion getters

		#region ToString, Equals, GetHashCode

		public override int GetHashCode()
		{
			int hashCode = DataType;
			return hashCode;
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("(");
			stringBuilder.Append(ToStringProperties());
			stringBuilder.Append(")");

			return stringBuilder.ToString();
		}

		internal virtual string ToStringProperties()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("DataType='");
			stringBuilder.Append("0x");
			stringBuilder.Append(_dataType.ToString("X2"));
			stringBuilder.Append("'");

			return stringBuilder.ToString();
		}

		public override bool Equals(object obj)
		{
			Type objType = obj.GetType();
			if (this.GetType() == objType)
			{
				UserData userData2Compare = obj as UserData;
				return EqualsProperties(userData2Compare);
			}

			return false;
		}

		internal bool EqualsProperties(UserData userData2Compare)
		{
			return (this.DataType == userData2Compare.DataType);
		}

		#endregion ToString, Equals, GetHashCode
	}
}
